package org.example.autosuggest;

import java.util.Collection;

public class SuggestWithMysql {
    public static void main(String[] args) {
        LexerAndParserFactory lexerAndParserfactory = new ReflectionLexerAndParserFactory(
                com.neuronbit.parser.MySqlLexer.class, com.neuronbit.parser.MySqlParser.class);
        String sql = "CREATE TABLE ADF(SADF VARCHAR(10) NOT NULL COMMENT 'SDFA',SDF V";
        // sql = "CR";
//         sql = "CREATE ";
        // sql = "CREATE TA";
//         sql = "CREATE TABLE abc ";
//         sql = "CREATE TABLE abc(";
        // sql = "CREATE TABLE abc(a VARCHAR( ";
        // sql = "CREATE TABLE abc(a VARCHAR(10 ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) N";
        // sql = "CREATE TABLE abc(a VARCHAR(10) C";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL ";
//         sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL)";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY L";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(s)(";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(s)(P";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(s)(PARTITION ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(s)(PARTITION ss ";
        // sql = "CREATE TABLE abc(a VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(s)(PARTITION ss CO";
        //intellij 也无法提示，只是报错
//        sql = "CREATE TABLE t1(c1 VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(c2)(PARTITION p1 COMMENT 'cmt";
//        sql = "CREATE TABLE t1(c1 VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(c2)(PARTITION p1 COMMENT 'cmt'";
//        sql = "CREATE TABLE t1(c1 VARCHAR(10) NOT NULL) PARTITION BY LIST COLUMNS(c2)(PARTITION p1 COMMENT 'cmt');";
//        sql = "CREATE TABLE Persons (ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int, PRIMARY KEY (sdf, s)";
//        sql = "CREATE TABLE Persons (ID int NOT NULL default '1' ";
        sql="CREATE TABLE account_open_trans (" +
                "id INT(11) UNSIGNED not NULL AUTO_INCREMENT COMMENT '自增主键'," +
                "biz_seq_no VARCHAR(32) COLLATE utf8_bin DEFAULT '' COMMENT '业务流水号'," +
                "sys_seq_no VARCHAR(32) COLLATE utf8_bin DEFAULT '' COMMENT '系统流水号'," +
                "PRIMARY KEY (id)," +
                "KEY ide(biz_seq_no)," +
                "KEY idx_seq(sys_seq_no)" +
                ") engine = in";
        AutoSuggester suggester = new AutoSuggester(lexerAndParserfactory, sql);
        suggester.setCasePreference(CasePreference.UPPER);
        Collection<SuggestionItem> suggestions = suggester.suggestCompletions();
        if (null != suggestions && !suggestions.isEmpty()) {
            for (SuggestionItem suggestion : suggestions) {
                System.out.println(suggestion);
            }
        } else {
            System.out.println("suggestion is empty");
        }
    }
}
